home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / seahaven / util.c++ < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.5 KB  |  83 lines

  1. /*
  2.  * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * Author:  Terry Weissman
  19.  *          weissman@sgi.com
  20.  */
  21.  
  22. #include "seahaven.h"
  23.  
  24. #include <string.h>
  25.  
  26.  
  27.  
  28. unsigned long GetColor(char *name, char *gname, unsigned long def) {
  29.     XColor col1, col2;
  30.     if (hascolor && XAllocNamedColor(dpy, cmap, name, &col1, &col2)) {
  31.     return col2.pixel;
  32.     }
  33.     else if (hasgrey && XAllocNamedColor(dpy, cmap, gname, &col1, &col2)) {
  34.     return col2.pixel;
  35.     }
  36.     else {
  37.     return def;
  38.     }
  39. }
  40.  
  41.  
  42. void GetInterestingEvent(XEvent *event) {
  43.     XNextEvent(dpy, event);
  44.     while (event->type == Expose) {
  45.     if (event->xexpose.count == 0) score->repaint();
  46.     XNextEvent(dpy, event);
  47.     }
  48. }
  49.     
  50.  
  51. Window CreateButtonWindow(char *label, int x, int y, int gravity, int *width) {
  52.     static GC textgc = NULL, cleargc = NULL;
  53.     int w = XTextWidth(font, label, strlen(label)) + 4;
  54.     int h = font->ascent + font->descent + 4;
  55.     if (width) *width = w;
  56.     Pixmap pixmap = XCreatePixmap(dpy, toplevel, w, h,
  57.                   DefaultDepth(dpy, screen));
  58.     if (textgc == NULL) {
  59.     textgc = XCreateGC(dpy, toplevel, 0, NULL);
  60.     XSetForeground(dpy, textgc, GetColor("black", "black",
  61.                          BlackPixel(dpy, screen)));
  62.     XSetFont(dpy, textgc, font->fid);
  63.     cleargc = XCreateGC(dpy, toplevel, 0, NULL);
  64.     XSetForeground(dpy, cleargc,  backpixel);
  65.     }
  66.     XFillRectangle(dpy, pixmap, cleargc, 0, 0, w, h);
  67.     XDrawString(dpy, pixmap, textgc, 2, 2 + font->ascent,
  68.         label, strlen(label));
  69.  
  70.     XSetWindowAttributes attributes;
  71.     long valuemask = CWEventMask | CWBackPixmap | CWWinGravity;
  72.     attributes.event_mask = ButtonPressMask;
  73.     attributes.background_pixmap = pixmap;
  74.     attributes.win_gravity = gravity;
  75.     Window window = XCreateWindow(dpy, toplevel, x, y,
  76.                   w, h, 1, (int) CopyFromParent,
  77.                   InputOutput, (Visual *) CopyFromParent,
  78.                   valuemask, &attributes);
  79.     XMapWindow(dpy, window);
  80.     return window;
  81. }
  82.     
  83.